package com.example.parse_springboot.controller;

import com.example.parse_springboot.entity.LiteflowScript;
import com.example.parse_springboot.entity.Result;
import com.example.parse_springboot.mapper.ScriptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/script")
public class ScriptController {
    @Autowired
    private ScriptMapper mapper;

    @PostMapping("/update")
    public Result<String> update(@RequestBody LiteflowScript script) {
        boolean b = mapper.insertOrUpdate(script);
        if (b) {
            return Result.success("更新成功");
        } else {
            return Result.error("更新失败");
        }
    }

    @GetMapping("/delete")
    public Result<String> delete(long id) {
        int i = mapper.deleteById(id);
        if (i > 0) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }
}
